﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>超市管理系统</title>
    <link rel="stylesheet" href="css/public.css"/>
    <link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<!--头部-->
    <header class="publicHeader">
        <h1>超市管理系统</h1>
        <div class="publicHeaderR">
            <p><span>下午好！</span><span style="color: #fff21b"> Admin</span> , 欢迎你！</p>
            <a href="logout">退出</a>
        </div>
    </header>
<!--时间-->
    <section class="publicTime">
        <span id="time">2020年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
<!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
            <nav>
                <ul class="list">
                    <li><a href="billList.html">账单管理</a></li>
                    <li><a href="providerList.html">物品管理</a></li>
                    <li  id="active"><a href="userList.html">用户管理</a></li>
                    <!-- <li><a href="password.html">密码修改</a></li> -->
                    <li><a href="logout">退出系统</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>用户管理页面</span>
                <div class="search">
                    <!-- <span>用户名称：</span> -->
                    <!-- <input id="search_name" type="text" placeholder="请输入用户名称"/>
                    <input id="search_btn" type="button" value="查询"/> -->
                    <a href="userAdd.html">添加用户</a>
                </div>
            </div>
            <!--用户-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">用户编码</th>
                    <th width="20%">用户名称</th>
                    <th width="10%">性别</th>
                    <th width="10%">年龄</th>
                    <th width="10%">电话</th>
                    <th width="10%">用户类型</th>
                    <th width="30%">操作</th>
                </tr>
                <tr>
                    <td>hanlu</td>
                    <td>韩露</td>
                    <td>女</td>
                    <td>20</td>
                    <td>15918230478</td>
                    <td>经理</td>
                    <td>
                        <a href="userUpdate.html"><img src="img/xiugai.png" alt="修改" title="修改"/></a>
                        <a href="#" class="removeUser"><img src="img/schu.png" alt="删除" title="删除"/></a>
                    </td>
                </tr>
                <tr>
                    <td>PRO-CODE—001</td>
                    <td>测试供应商001</td>
                    <td>韩露</td>
                    <td>15918230478</td>
                    <td>15918230478</td>
                    <td>2020-11-12</td>
                    <td>
                        <a href="userUpdate.html"><img src="img/xiugai.png" alt="修改" title="修改"/></a>
                        <a href="#" class="removeUser"><img src="img/schu.png" alt="删除" title="删除"/></a>
                    </td>
                </tr>
            </table>
        </div>
    </section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>

    <footer class="footer">
    </footer>

<script src="js/jquery.js"></script>
<script src="js/js.js"></script>
<script src="js/time.js"></script>
<script src="js/axios.min.js"></script>
<script>
    function start(){
        axios({
            url: 'user',
            method: 'GET'
        }).then(result => {
            const list = result.data.data
            let str = `<tr class="firstTr">
                        <th width="10%">用户编码</th>
                        <th width="20%">昵称</th>
                        <th width="10%">用户名</th>
                        <th width="10%">密码</th>
                        <th width="10%">电话</th>
                        <th width="10%">用户类型</th>
                        <th width="30%">操作</th>
                    </tr>`

            // 将 JSON 字符串解析为 JavaScript 对象或数组
            
            console.log(list)
            
            list.forEach(item => {
                const {id, nickname, username, password, phone, role} = item
                str += `
                <tr>
                    <td>${id}</td>
                    <td>${nickname}</td>
                    <td>${username}</td>
                    <td>${password}</td>
                    <td>${phone}</td>
                    <td>${role === 1 ? '管理员' : '普通用户'}</td>
                    <td>
                        <a href="#" class="removeUser"><img src="img/schu.png" alt="删除" title="删除" data-id='${id}' /></a>
                    </td>
                </tr>
                `
            })
            document.querySelector('.providerTable').innerHTML=str
            const ls = document.querySelectorAll('.removeUser')
            for(let i = 0; i < ls.length; i++){
                ls[i].addEventListener('click', function(e){
                    console.log(e.target.dataset.id)

                    $('.zhezhao').css('display', 'block');
                    $('#removeUse').fadeIn();
                    document.querySelector('#yes').setAttribute('data-id', e.target.dataset.id)
                })
            }
        });
    }
    
    start();

    document.querySelector('#yes').addEventListener('click', function(e){
        $('.zhezhao').css('display', 'none');
        $('#removeUse').fadeOut();
        axios({
            url: 'del',
            method: 'POST',
            params: {
                id: e.target.dataset.id
            }
        }).then(result => {
            alert(result.data.data)
            start();
        })
    })
    
</script>

</body>
</html>